<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function(){
	var btn=document.getElementById("btn1");
	var ul=document.getElementById("ul1");
	var txt=document.getElementById("txt");
	btn.onclick=function(){
		var li=document.createElement("li");
		var aLi=ul.getElementsByTagName("li");
		li.innerHTML=txt.value;
		//追加元素
		//ul.appendChild(li);	
		
		//在元素前面添加元素
		//ul.insertBefore(li,aLi[0]);
		
		if(aLi.length==0){
			ul.appendChild(li);	
		}else{
			ul.insertBefore(li,aLi[0]);	
		}
	};	
};
</script>
</head>

<body>
<input id="txt" type="text" value="" />
<input id="btn1" type="button" value="创建li" />
<ul id="ul1">
</ul>
</body>
</html>
